<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>splice()</title>
	</head>
	<body>
		<p id="old"></p>
		<p id="mynew">点击按钮添加和删除元素</p>
		<button onclick="my()">点击</button>
		<script>
			function my(){
				var old=document.getElementById('old');
				var mynew=document.getElementById("mynew");
				//定义数组
				var fruits=["banana","orange","apple","mango"];
				old.innerHTML=fruits;
				//在orange元素之后，添加元素
				fruits.splice(2,0,"pear","peach");
				mynew.innerHTML=fruits;
				//在orange元素之后，删除2个元素
				fruits.splice(2,2);
				mynew.innerHTML=fruits;
				//设置p标签
			}
		</script>
	</body>
</html>
